package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.MemberTypeAndRoleIdVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.MemberTypeIdVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.RoleIdVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.*;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.*;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.*;
import com.ssy.lingxi.member.merchant.model.vo.validate.request.MemberValidateVO;
import com.ssy.lingxi.member.merchant.model.vo.validate.request.ValidateIdPageVO;
import com.ssy.lingxi.member.merchant.model.vo.validate.response.MemberValidateDetailLevelVO;
import com.ssy.lingxi.member.merchant.service.web.*;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 平台后台 - 平台会员管理 - 会员维护
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-13
 */
@RestController
@RequestMapping("/member/maintenance")
public class PlatformMemberMaintenanceController {

    @Resource
    private IPlatformMemberMaintenanceService memberMaintenanceService;

    @Resource
    private IPlatformMemberDetailBasicService memberDetailBasicService;

    @Resource
    private IPlatformMemberDetailLevelService memberDetailLevelService;

    @Resource
    private IPlatformMemberDetailAuthService memberDetailAuthService;

    @Resource
    private IPlatformMemberDetailRightService memberDetailRightService;

    @Resource
    private IPlatformMemberDetailCreditService memberDetailCreditService;

    /**
     * 获取模糊分页查询会员页面的查询下拉框内容
     * @return 操作结果
     */
    @RequestMapping(value = "/pageitems", method = RequestMethod.GET)
    public Wrapper<PlatformMemberQuerySearchConditionVO> getPageCondition(@RequestHeader HttpHeaders headers) {
        return memberMaintenanceService.getPageCondition(headers);
    }

    /**
     * 分页、模糊查询会员信息列表
     * @param headers HttpHeaders信息
     * @param queryVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformPageQueryMemberVO>> pageMembers(@RequestHeader HttpHeaders headers, @Valid PlatformMemberQueryVO queryVO) {
        return memberMaintenanceService.pageMembers(headers, queryVO);
    }

    /**
     * 获取新增会员页面的内容
     * @param headers HttpHeaders信息
     * @return 操作结果
     */
    @RequestMapping(value = "/addpageitems", method = RequestMethod.GET)
    public Wrapper<PlatformAddMemberPageItemsVO> getAddMemberPageItems(@RequestHeader HttpHeaders headers) {
        return memberMaintenanceService.getAddMemberPageItems(headers);
    }

    /**
     * 新增会员页面，根据会员类型，查询角色列表
     * @param headers HttpHeader信息
     * @param idVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/addpageitems/role", method = RequestMethod.GET)
    public Wrapper<List<RoleIdAndNameVO>> getAddMemberPageRoles(@RequestHeader HttpHeaders headers, @Valid MemberTypeIdVO idVO) {
        return memberMaintenanceService.getAddMemberPageRoles(headers, idVO);
    }

    /**
     * 新增会员页面，根据会员类型和角色，查询等级列表
     * @param headers HttpHeader信息
     * @param typeAndRoleIdVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/addpageitems/level", method = RequestMethod.GET)
    public Wrapper<List<LevelAndTagVO>> getAddMemberPageLevels(@RequestHeader HttpHeaders headers, @Valid MemberTypeAndRoleIdVO typeAndRoleIdVO) {
        return memberMaintenanceService.getAddMemberPageLevels(headers, typeAndRoleIdVO);
    }

    /**
     * 新增会员页面，根据选择的角色，返回会员注册资料信息
     * @param headers HttpHeaders信息
     * @param idVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/addpageitems/detail", method = RequestMethod.GET)
    public Wrapper<List<MemberConfigGroupVO>> getAddMemberPageMemberConfigItems(@RequestHeader HttpHeaders headers, @Valid RoleIdVO idVO) {
        return memberMaintenanceService.getAddMemberPageMemberConfigItems(headers, idVO);
    }

    /**
     * 新增会员
     * @param headers HttpHeaders信息
     * @param memberVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/addmember")
    public Wrapper<Void> addMember(@RequestHeader HttpHeaders headers, @RequestBody @Valid PlatformAddMemberVO memberVO) {
        return memberMaintenanceService.addMember(headers, memberVO);
    }

    /**
     * 新增会员页面，查询用户基本信息
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 会员基本信息
     */
    @RequestMapping(value = "/getmember", method = RequestMethod.GET)
    public Wrapper<PlatformMemberMaintenanceMemberDetailVO> getMemberDetail(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberMaintenanceService.getMemberDetail(headers, validateVO);
    }

    /**
     * 修改会员
     * @param headers Http头部信息
     * @param memberVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/updatemember")
    public Wrapper<Void> updateMemberDetail(@RequestHeader HttpHeaders headers, @RequestBody @Valid PlatformUpdateMemberVO memberVO) {
        return memberMaintenanceService.updateMemberDetail(headers, memberVO);
    }

    /**
     * 更改会员状态（冻结、解冻会员）
     * @param headers HttpHeaders信息
     * @param statusVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/status")
    public Wrapper<Void> changeMemberStatus(@RequestHeader HttpHeaders headers, @RequestBody @Valid ChangeMemberStatusVO statusVO) {
        return memberMaintenanceService.changeMemberStatus(headers, statusVO);
    }

    /**
     * 删除会员
     * @param headers Http头部信息
     * @param validateVO 接口参数
     * @return 删除结果
     */
    @RequestMapping("/delete")
    public Wrapper<Void> deleteMember(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberValidateVO validateVO) {
        return memberMaintenanceService.deleteMember(headers, validateVO);
    }

    /**
     * 获取会员批量导入模板下载Url
     * @param request 客户端请求
     * @param response 客户端响应
     */
    @RequestMapping(value = "/gettemplate", method = RequestMethod.GET)
    public void getMemberImportTemplateFile(HttpServletRequest request, HttpServletResponse response) {
        memberMaintenanceService.getMemberImportFile(request, response);
    }

    /**
     * 批量导入会员信息
     * @param headers HttpHeaders信息
     * @param excelFile 上传的文件
     * @return 操作结果
     */
    @RequestMapping("/import")
    public Wrapper<Void> importMembers(@RequestHeader HttpHeaders headers, @RequestParam("memberImport") MultipartFile excelFile) {
        return memberMaintenanceService.importMembers(headers, excelFile);
    }

    /**
     * 查询批量导入的批次号列表
     * @param headers HttpHeaders信息
     * @return 操作结果
     */
    @RequestMapping(value = "/import/getbatch", method = RequestMethod.GET)
    public Wrapper<List<String>> getImportBatchNo(@RequestHeader HttpHeaders headers) {
        return memberMaintenanceService.getImportBatchNo(headers);
    }

    /**
     * 根据批次号，删除批量导入的会员
     * @param headers HttpHeaders信息
     * @param memberVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/import/delbatch")
    public Wrapper<Void> deleteMembersByBatchNo(@RequestHeader HttpHeaders headers, @RequestBody @Valid BatchDeleteMemberVO memberVO) {
        return memberMaintenanceService.deleteMembersByBatchNo(headers, memberVO);
    }

    /**
     * 会员详情 - 基本信息
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/basic", method = RequestMethod.GET)
    public Wrapper<PlatformMemberDetailBasicVO> getMemberDetailBasic(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailBasicService.getMemberDetailBasic(headers, validateVO);
    }

    /**
     * 会员详情 - 会员权限信息 - 获取会员菜单权限
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/auth/menu", method = RequestMethod.GET)
    public Wrapper<List<AuthTreeMenuVO>> getMemberDetailAuth(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailAuthService.getMemberDetailAuthMenu(headers, validateVO);
    }

    /**
     * 会员详情 - 会员权限信息 - 获取会员菜单关联的按钮列表
     * @param headers HttpHeaders信息
     * @param queryButtonVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/auth/button", method = RequestMethod.GET)
    public Wrapper<List<AuthTreeButtonVO>> getMemberDetailAuthButton(@RequestHeader HttpHeaders headers, @Valid PlatformMemberDetailQueryButtonVO queryButtonVO) {
        return memberDetailAuthService.getMemberDetailAuthButton(headers, queryButtonVO);
    }

    /**
     * 查询左侧树形权限菜单中勾选的Id列表
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/auth/menu/check", method = RequestMethod.GET)
    public Wrapper<AuthTreeMenuButtonCheckIdVO> getTreeCheckIds(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailAuthService.getTreeCheckIds(headers, validateVO);
    }

    /**
     * 根据左侧勾选的菜单，查询右侧勾选的按钮Id列表
     * @param headers HttpHeaders信息
     * @param queryButtonVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/auth/button/check", method = RequestMethod.GET)
    public Wrapper<AuthTreeMenuButtonCheckIdVO> getButtonCheckIds(@RequestHeader HttpHeaders headers, @Valid PlatformMemberDetailQueryButtonVO queryButtonVO) {
        return memberDetailAuthService.getButtonCheckIds(headers, queryButtonVO);
    }

    /**
     * 更新左侧菜单权限
     * @param updateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/detail/auth/menu/update")
    public Wrapper<Void> updateMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid RoleUpdateVO updateVO) {
        return memberDetailAuthService.updateMemberRole(headers, updateVO);
    }

    /**
     * 更新权限菜单关联的按钮
     * @param headers HttpHeaders信息
     * @param updateButtonVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/detail/auth/button/update")
    public Wrapper<Void> updateMemberRoleButton(@RequestHeader HttpHeaders headers, @RequestBody @Valid RoleUpdateButtonVO updateButtonVO) {
        return memberDetailAuthService.updateMemberRoleButton(headers, updateButtonVO);
    }

    /**
     * 会员详情 - 等级信息 - 会员等级
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/level/basic", method = RequestMethod.GET)
    public Wrapper<MemberValidateDetailLevelVO> getMemberDetailLevel(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailLevelService.getMemberDetailLevel(headers, validateVO);
    }

    /**
     * 会员详情 - 等级信息 - 分页查询会员等级历史记录（活跃分获取记录）
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/level/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailLevelHistoryVO>> pageMemberLevelDetailHistory(@RequestHeader HttpHeaders headers,  @Valid ValidateIdPageVO pageVO) {
        return memberDetailLevelService.pageMemberLevelDetailHistory(headers, pageVO);
    }


    /**
     * 会员详情 - 权益信息 - 权益基本信息
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/right/basic", method = RequestMethod.GET)
    public Wrapper<MemberDetailRightVO> getMemberDetailRight(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailRightService.getMemberDetailRight(headers, validateVO);
    }

    /**
     * 会员详情 - 权益信息 - 分页查询会员权益获取记录
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/right/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailRightHistoryVO>> pageMemberDetailRightHistory(@RequestHeader HttpHeaders headers, @Valid ValidateIdPageVO pageVO) {
        return memberDetailRightService.pageMemberDetailRightHistory(headers, pageVO);
    }

    /**
     * 会员详情 - 权益信息 - 分页查询会员权益使用记录
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/right/spend/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailRightSpendHistoryVO>> pageMemberDetailRightSpendHistory(@RequestHeader HttpHeaders headers, @Valid ValidateIdPageVO pageVO) {
        return memberDetailRightService.pageMemberDetailRightSpendHistory(headers, pageVO);
    }


    /**
     * 会员详情 - 会员信用信息 - 基本信息
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/basic", method = RequestMethod.GET)
    public Wrapper<MemberDetailCreditVO> getMemberDetailCredit(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailCreditService.getMemberDetailCredit(headers, validateVO);
    }

    /**
     * 会员详情 - 会员信用信息 - 交易评价汇总
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/trade/summary", method = RequestMethod.GET)
    public Wrapper<MemberDetailCreditCommentSummaryVO> getMemberDetailCreditTradeCommentSummary(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailCreditService.getMemberDetailCreditTradeCommentSummary(headers, validateVO);
    }

    /**
     * 会员详情 - 会员信用信息 - 分页查询交易评价历史记录
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailCreditTradeHistoryVO>> pageMemberDetailCreditTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberDetailCreditHistoryPageVO pageVO) {
        return memberDetailCreditService.pageMemberDetailCreditTradeCommentHistory(headers, pageVO);
    }

    /**
     * 会员详情 - 会员信用信息 - 售后评价汇总
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/aftersale/summary", method = RequestMethod.GET)
    public Wrapper<MemberDetailCreditCommentSummaryVO> getMemberDetailCreditAfterSaleCommentSummary(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailCreditService.getMemberDetailCreditAfterSaleCommentSummary(headers, validateVO);
    }

    /**
     * 会员详情 - 会员信用信息 - 分页查询售后评价历史记录
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/aftersale/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailCreditAfterSaleHistoryVO>> pageMemberDetailCreditAfterSaleCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberDetailCreditHistoryPageVO pageVO) {
        return memberDetailCreditService.pageMemberDetailCreditAfterSaleCommentHistory(headers, pageVO);
    }

    /**
     * 会员详情 - 会员信用信息 - 投诉汇总
     * @param headers HttpHeaders信息
     * @param validateVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/complain/summary", method = RequestMethod.GET)
    public Wrapper<MemberDetailCreditComplainSummaryVO> getMemberDetailCreditComplainSummary(@RequestHeader HttpHeaders headers, @Valid MemberValidateVO validateVO) {
        return memberDetailCreditService.getMemberDetailCreditComplainSummary(headers, validateVO);
    }

    /**
     * 会员详情 - 会员信用信息 - 分页查询投诉历史记录
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/detail/credit/complain/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailCreditComplainHistoryVO>> pageMemberDetailCreditComplainHistory(@RequestHeader HttpHeaders headers, @Valid ValidateIdPageVO pageVO) {
        return memberDetailCreditService.pageMemberDetailCreditComplainHistory(headers, pageVO);
    }
}
